// pages/student/detail/index.js
import {StudentModel} from "../../../models/student/StudentModel";

const studentModel = new StudentModel()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    studentDetail: [],
    recommendStudentList:[],
    studentSubject:[],

    stId: '',
    current: 1,
    pageSize: 10


  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let stId = options.stId
    this.data.stId = stId
    this._init(stId,this.data.current,this.data.pageSize)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  _init(stId,current,pageSize){
    const getDetail = studentModel.getStudentDetail(stId)
    const getRe = studentModel.getRecommendStudent(stId,current,pageSize)
    // const getSubject = studentModel.getStudentSubject(stId,current,pageSize)
    Promise.all([getDetail,getRe])
        .then(res=>{
          this.setData({
            studentDetail: res[0],
            recommendStudentList: res[1]

          })
        })
        .catch(err=>{
          console.log(err);
        })
  },

  moreStudentTap(){
    wx.navigateTo({
      url: '../all/index'
    })
  }
})